package model;

import java.util.Collection;
import java.util.Iterator;
import java.util.Vector;

/**
 * The Observee class offers methods to re/deregister Observers and to notify all Observers with an Event.
 *
 */
public abstract class Observee {
	
	final Collection<Observer> observer;
	
	Observee(){
		this.observer = new Vector<Observer>();
	}
	
	/**
	 * Adds the provided Observer to the list of observers.
	 * @param o is the Observer to add
	 */
	public void register(final Observer o){
		this.observer.add(o);
	}
	/**
	 * Removes the provided Observer from the list of observers.
	 * @param o is the Observer to remove.
	 */
	public void deregister(final Observer o){
		this.observer.remove(o);
	}
	/**
	 * Notifies all observers with the provided event.
	 * @param event is the event all observers will receive.
	 */
	public void notifyObserver(final Event event){
		final Iterator<Observer> obs = this.observer.iterator();
		while (obs.hasNext()){
			final Observer current = obs.next();
			current.update(event);
		}
	}
}